package tiantao.taogu.TgEnum;

import java.util.HashSet;
import java.util.Set;

/**
 * 新后台权限/功能
 * @author renyongzhen
 *
 */
public enum AuthrityEnum {
  TJ_DICTIONARIES_MANAGEMENT_95("字典管理","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_DICTIONARIES_MANAGEMENT_95_1("基础字典","TJ_95-1","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_DICTIONARIES_MANAGEMENT_95_2("套餐类型","TJ_95-2","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_DICTIONARIES_MANAGEMENT_95_3("套餐字典","TJ_95-3","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_DICTIONARIES_MANAGEMENT_95_4("企业标签字典","TJ_95-4","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_DICTIONARIES_MANAGEMENT_95_5("提醒设置","TJ_95-5","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_DICTIONARIES_MANAGEMENT_95_6("体检机构管理","TJ_95-6","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_DICTIONARIES_MANAGEMENT_95_7("体检中心管理","TJ_95-7","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_DICTIONARIES_MANAGEMENT_95_8("组合项目维护","TJ_95-8","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_95_9("预约时段配置","TJ_95-9","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_95_10("号源规则管理","TJ_95-10","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_95_11("号源管理","TJ_95-11","TJ_95",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),

  TJ_EXAMINATION_MANAGEMENT_96("体检预约管理","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_96_1("号别维护","TJ_96-1","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_96_2("号源维护","TJ_96-2","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_96_3("压力查询","TJ_96-3","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_96_4("检前提醒","TJ_96-4","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_96_5("个人预约记录","TJ_96-5","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_96_6("个人体检记录","TJ_96-6","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_96_7("企业预约记录","TJ_96-7","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_EXAMINATION_MANAGEMENT_96_8("团检记录","TJ_96-8","TJ_96",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),

  TJ_ENTERPRISE_MANAGEMENT_97("企业管理","TJ_97",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_97_1("企业信息管理","TJ_97-1","TJ_97",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_97_2("注册审核管理","TJ_97-2","TJ_97",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_97_3("企业员工管理","TJ_97-3","TJ_97",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_97_4("管理端机构列表","TJ_97-4","TJ_97",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_97_5("企业套餐预约","TJ_97-5","TJ_97",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_97_6("企业人员预约","TJ_97-6","TJ_97",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),

  TJ_ENTERPRISE_MANAGEMENT_98("体检财务管理","TJ_98",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_98_1("订单管理","TJ_98-1","TJ_98",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_98_2("收退费查询","TJ_98-2","TJ_98",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER}),
  TJ_ENTERPRISE_MANAGEMENT_98_3("收支分析","TJ_98-3","TJ_98",new UserTypeEnum[]{},new UserTypeEnum[]{UserTypeEnum.HIS_ADMIN,UserTypeEnum.HOSPITAL_ADMIN,UserTypeEnum.PROJECTS_MASTER});
  ;


  private String name;

  
  private String id;
  
  /**
   * 自动选择此权限的角色集合
   */
  private Set<UserTypeEnum> autoSelected;

  /**
   * 可选此权限的角色集合
   */
  private Set<UserTypeEnum> canSelect;
  
  private String parentId;
  
  
  /**
   * 
   * @param name  权限名称
   * @param id
   * @param parentId 父权限id（可空）
   * @param autoSelected  自动拥有此权限的角色
   * @param canSelect  可选择此权限的角色
   */
  private AuthrityEnum(String name, String id, String parentId, UserTypeEnum[] autoSelected, UserTypeEnum[] canSelect){
    this.name = name;
    this.id = id;
    this.autoSelected = new HashSet<UserTypeEnum>();
    this.parentId = parentId;
    if(autoSelected!=null){
      for(UserTypeEnum t:autoSelected){
        this.autoSelected.add(t);
      }
    }
    
    this.canSelect = new HashSet<UserTypeEnum>();
    if(canSelect!=null){
      for(UserTypeEnum t:canSelect){
        this.canSelect.add(t);
      }
    }
  }
  
  private AuthrityEnum(String name, String id, UserTypeEnum[] autoSelected, UserTypeEnum[] canSelect){
    this(name, id, null, autoSelected, canSelect);
  }

  public String getName() {
    return name;
  }

  public String getId() {
    return id;
  }

  public boolean isAutoSelected(UserTypeEnum userType) {
    return this.autoSelected.contains(userType);
  }

  public boolean isCanSelect(UserTypeEnum userType) {
    return this.canSelect.contains(userType);
  }

  public Set<UserTypeEnum> getUserRoles(){
      Set<UserTypeEnum> set = new HashSet<UserTypeEnum>();
      set.addAll(autoSelected);
      set.addAll(canSelect);
      return set;
  }

  public String getParentId() {
    return parentId;
  }

  public void setParentId(String parentId) {
    this.parentId = parentId;
  }

  public static AuthrityEnum getById(String moduleId) {
    for(AuthrityEnum e:AuthrityEnum.values()){
      if(e.getId().equals(moduleId)){
        return e;
      }
    }
    return null;
  }
  
}
